package com.campus.backend.controller;

import com.campus.backend.bean.order.OrderQueryParam;
import com.campus.backend.service.OrderService;
import com.campus.backend.vo.order.OrderVo;
import com.campus.common.bean.common.Pagination;
import com.campus.common.bean.common.Resp;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author ZhaoYuJie
 * @since 2025-05-21
 */
@Api(tags = "订单管理")
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 分页查询订单列表
     *
     * @param param 查询参数
     * @return 分页结果
     */
    @ApiOperation("分页查询订单列表")
    @GetMapping("/page")
    public Resp<Pagination<OrderVo>> page(@Validated OrderQueryParam param) {
        PageInfo<OrderVo> pageInfo = orderService.getOrderListPage(param);
        return Resp.successPageable(pageInfo);
    }

    /**
     * 获取订单详情
     *
     * @param orderId 订单ID
     * @return 订单详情
     */
    @ApiOperation("获取订单详情")
    @GetMapping("/detail/{orderId}")
    public Resp<OrderVo> getOrderDetail(@PathVariable String orderId) {
        OrderVo orderVo = orderService.getOrderDetail(orderId);
        return Resp.success(orderVo);
    }
}
